﻿using System;
using MongoDB;
using T0yK4T.IO;
using System.Collections.Generic;

namespace ToyChat
{
    /// <summary>
    /// This interface describes a common way of accessing multiple channels
    /// </summary>
    public interface IChannelHandler : IEnumerable<IChannel>
    {
        /// <summary>
        /// Gets the channel with the specified ID if it exists
        /// </summary>
        /// <param name="channelID">The ID of the channel to get</param>
        /// <returns>An instance of <see cref="IChannel"/> that represents the channel</returns>
        IChannel this[int channelID] { get; }

        /// <summary>
        /// Gets the channel with the specified name if it exists
        /// </summary>
        /// <param name="channelName">The name of the channel to get</param>
        /// <returns>An instance of <see cref="IChannel"/> that represents the channel</returns>
        IChannel this[string channelName] { get; }

        /// <summary>
        /// Removes the specified user from all channels
        /// </summary>
        /// <param name="user">The user to remove</param>
        void RemoveUser(IUser user);

        /// <summary>
        /// Attempts to get the channel with the specified ID and returns a value indicating whether or not the operation was succesfuly
        /// </summary>
        /// <param name="channelID">The ID of the channel to get</param>
        /// <param name="channel">Will contain an instance of <see cref="IChannel"/> that represents the channel</param>
        /// <returns>True if succesful, otherwise false</returns>
        bool TryGetChannel(int channelID, out IChannel channel);

        /// <summary>
        /// Attempts to get the channel with the specified name and returns a value indicating whether or not the operation was succesfuly
        /// </summary>
        /// <param name="channelName">The name of the channel to get</param>
        /// <param name="channel">Will contain an instance of <see cref="IChannel"/> that represents the channel</param>
        /// <returns>True if succesful, otherwise false</returns>
        bool TryGetChannel(string channelName, out IChannel channel);

        /// <summary>
        /// Attempts to create a new channel with the specified name
        /// </summary>
        /// <param name="channelName">The name of the newly created channel</param>
        /// <param name="channel">Will be an instance of <see cref="IChannel"/> with the specified name if the channel was created succesfully</param>
        /// <returns>True if succesful, otherwise false</returns>
        bool CreateChannel(string channelName, out IChannel channel);

        /// <summary>
        /// Deletes the specified channel
        /// </summary>
        /// <param name="channel">The channel to delete</param>
        void DeleteChannel(IChannel channel);

        /// <summary>
        /// Stores (or updates) the specified channel in the database
        /// <para/>
        /// (Saves changes made to the specified channel object)
        /// </summary>
        /// <param name="channel">The channel to save</param>
        void UpdateDB(IChannel channel);

        /// <summary>
        /// Gets the default channel (ID: 1)
        /// </summary>
        IChannel DefaultChannel { get; }
    }
}
